"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const maishu_node_mvc_1 = require("maishu-node-mvc");
const typeorm_1 = require("typeorm");
// import { config } from "./config";
const path = require("path");
const common_1 = require("./common");
exports.connection = maishu_node_mvc_1.createParameterDecorator(async () => {
    let connectionManager = typeorm_1.getConnectionManager();
    if (!connectionManager.has(common_1.settings.db.database)) {
        let dbOptions = {
            type: "mysql",
            host: common_1.settings.db.host,
            port: common_1.settings.db.port,
            username: common_1.settings.db.user,
            password: common_1.settings.db.password,
            database: common_1.settings.db.database,
            synchronize: true,
            logging: true,
            entities: [path.join(__dirname, "entities.js")],
            name: common_1.settings.db.database,
        };
        await typeorm_1.createConnection(dbOptions);
    }
    let connection = typeorm_1.getConnection(common_1.settings.db.database);
    return Promise.resolve(connection);
});
